function [p_lwr] = bino_lwr(n, x, aa)

%   lower limit of confidence interval for 100(1-aa)%
tol = 10^(-10);

p_lwr = [];
for k = 1 : length(x)
    p10 = eps;      p20 = 1 - eps;      p = (p10 + p20)/2;
    upr = 1 - binocdf(x(k,1), n, p);

    while (aa < upr) | (aa - upr > tol)
        if aa > upr
            p10 = p;    p = (p10 + p20)/2;
        else
            p20 = p;    p = (p10 + p20)/2;
        end
        upr = 1-binocdf(x(k,1), n, p);
        if p < eps | p > 1-eps
            break;
        else
        end
    end
    p_lwr = [p_lwr; p];
end
